﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Controls
{
    public partial class SwitchCheckBox : CheckBox
    {
        private Image mCheckImage;
        private Image mUnCheckImage;
        private bool bRatioLock = false;
        public SwitchCheckBox()
        {
            InitializeComponent();
            this.Appearance = Appearance.Button;
            this.Text = string.Empty;
            this.AutoSize = false;
            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderSize = 0;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.Size = new Size(40, 40);
            this.BackColor = SystemColors.Window;

            this.CheckedChanged += SwitchButton_CheckedChanged;
            this.FlatAppearance.MouseDownBackColor = Color.FromArgb(226, 226, 226);
            this.FlatAppearance.MouseOverBackColor = Color.FromArgb(226, 226, 226);
            this.BackColor = Color.FromArgb(226, 226, 226);
        }

        private void SwitchButton_CheckedChanged(object sender, EventArgs e)
        {
            if (this.Checked)
                this.BackgroundImage = mCheckImage;
            else
                this.BackgroundImage = mUnCheckImage;

        }
        public Image CheckImage
        {
            set
            {
                mCheckImage = value;
            }
            get
            {
                return mCheckImage;
            }
        }
        public Image UnCheckImage
        {
            set
            {
                mUnCheckImage = value;
            }
            get
            {
                return mUnCheckImage;
            }
        }
        public bool RatioLock
        {
            set
            {
                bRatioLock = value;
            }
            get
            {
                return bRatioLock;
            }
        }
        private void SwitchButton_Paint(object sender, PaintEventArgs e)
        {
            if (this.Checked)
            {
                this.BackgroundImage = mCheckImage;
            }
            else
            {
                this.BackgroundImage = mUnCheckImage;
            }
        }
    }
}
